using UnityEngine;
using System.Collections;
using Phidgets;
using Phidgets.Events;

public class PhidgetSensors : MonoBehaviour {
	
	InterfaceKit ifKit;
	
	int count2 = 0;
	
	// Use this for initialization
	void Start () {
		
		try
		{
			//Initialize the InterfaceKit object
     		ifKit = new InterfaceKit();	
			
			//Specific event handler
			ifKit.InputChange += new InputChangeEventHandler(ifKit_InputChange);
			ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);
		                
			//Open the object for device connections
        	ifKit.open();
		
			//ifKit.waitForAttachment();
			ifKit.waitForAttachment(3000);
			
					
		}
		
		catch
		{
			System.Console.WriteLine("Phidget issues");			
		}
	}
	
	// Update is called once per frame
	void Update () {
	
		GameVariables.axisX = 1000 - ifKit.sensors[1].Value;
		GameVariables.axisY = ifKit.sensors[0].Value;
		
		if (GameVariables.currentPlayer == 0) {			
			GameVariables.speed0 = (ifKit.sensors[2].Value)/25;
		}
		else {
			GameVariables.speed1 = (ifKit.sensors[2].Value)/25;
		}
	
		GameVariables.launch = ifKit.sensors[3].Value;
	
	}
	
	static void ifKit_InputChange(object sender, InputChangeEventArgs e)
    {
		print("Input "+ e.Index +" value "+ e.Value.ToString());
		GameVariables.whichSensor = e.Index;
	}
	
	static void ifKit_SensorChange(object sender, SensorChangeEventArgs e)
    {
		print("Sensor "+ e.Index +" value "+ e.Value);		
        GameVariables.whichSensor = e.Index;
	}

}